package com.xez.views
{
	import flash.events.MouseEvent;
	
	import mx.graphics.BitmapFillMode;
	import mx.graphics.BitmapScaleMode;
	
	import spark.components.Image;
	
	public class ImageComponent extends Image
	{
		public function ImageComponent()
		{
			super();
			
			fillMode= BitmapFillMode.SCALE;
			scaleMode= BitmapScaleMode.LETTERBOX;
			doubleClickEnabled = true;
			
			addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler);
		}
		
		public var isZoom:Boolean = false;
		private var oldSizeObj:Object = new Object();
		
		public function reset():void
		{
			if (isZoom && oldSizeObj)
			{
				width = oldSizeObj.width;
				height = oldSizeObj.height;
				isZoom = false;
			}
		}
		
		private function doubleClickHandler(e:MouseEvent):void
		{
			if (!isZoom)
				goZoom();
			else
				backZoom();
		}
		
		private function goZoom():void
		{
			// 开始放大图片
			if (bitmapData)
			{
				oldSizeObj.height = height;
				oldSizeObj.width = width;
				
				width = bitmapData.width;
				height = bitmapData.height;
				isZoom = true;
			}
		}
		
		private function backZoom():void
		{
			if (!oldSizeObj)
				return;
			
			width = oldSizeObj.width;
			height = oldSizeObj.height;
			isZoom = false;
		}
		
	}
}